﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gfLibrary;
using DBUtility;
using Model;
using BLL;

namespace GreatGF
{
    public partial class DEV_STANDARD_LAMP_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    DEV_STANDARD_LAMP_BLL m_DEV_STANDARD_LAMP_BLL = new DEV_STANDARD_LAMP_BLL();

                    if(m_DEV_STANDARD_LAMP_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        DEV_STANDARD_LAMP m_DEV_STANDARD_LAMP = new DEV_STANDARD_LAMP();
                        m_DEV_STANDARD_LAMP = m_DEV_STANDARD_LAMP_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_DEV_STANDARD_LAMP.ID.ToString();
                        txtSEARCH_CONDITION.Text = m_DEV_STANDARD_LAMP.SEARCH_CONDITION;
                        txtZXMC.Text = m_DEV_STANDARD_LAMP.ZXMC;
                        txtYDZDGGQXZ.Text = m_DEV_STANDARD_LAMP.YDZDGGQXZ;
                        txtEDZDGGQXZ.Text = m_DEV_STANDARD_LAMP.EDZDGGQXZ;
                        txtSDZDGGQXZ.Text = m_DEV_STANDARD_LAMP.SDZDGGQXZ;
                        txtYGCZPYXZXX.Text = m_DEV_STANDARD_LAMP.YGCZPYXZXX;
                        txtYGCZPYXZSX.Text = m_DEV_STANDARD_LAMP.YGCZPYXZSX;
                        txtJGCZPYXZXX.Text = m_DEV_STANDARD_LAMP.JGCZPYXZXX;
                        txtJGCZPYXZSX.Text = m_DEV_STANDARD_LAMP.JGCZPYXZSX;
                        txtYGZDZPXZ.Text = m_DEV_STANDARD_LAMP.YGZDZPXZ;
                        txtYGZDYPXZ.Text = m_DEV_STANDARD_LAMP.YGZDYPXZ;
                        txtYGYDZPXZ.Text = m_DEV_STANDARD_LAMP.YGYDZPXZ;
                        txtYGYDYPXZ.Text = m_DEV_STANDARD_LAMP.YGYDYPXZ;
                        txtJGZDZPXZ.Text = m_DEV_STANDARD_LAMP.JGZDZPXZ;
                        txtJGZDYPXZ.Text = m_DEV_STANDARD_LAMP.JGZDYPXZ;
                        txtJGYDZPXZ.Text = m_DEV_STANDARD_LAMP.JGYDZPXZ;
                        txtJGYDYPXZ.Text = m_DEV_STANDARD_LAMP.JGYDYPXZ;
                        txtZGQXZ.Text = m_DEV_STANDARD_LAMP.ZGQXZ;
                        txtIS_SHOW.Text = m_DEV_STANDARD_LAMP.IS_SHOW.ToString();
                        txtAREA_NAME.Text = m_DEV_STANDARD_LAMP.AREA_NAME;
                        txtUTYPE.Text = m_DEV_STANDARD_LAMP.UTYPE.ToString();
                        txtBIG1000JGCZPYXZXX.Text = m_DEV_STANDARD_LAMP.BIG1000JGCZPYXZXX;
                        txtBIG1000JGCZPYXZSX.Text = m_DEV_STANDARD_LAMP.BIG1000JGCZPYXZSX;
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "DEV_STANDARD_LAMP_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtSEARCH_CONDITION.ReadOnly = true;
                        txtSEARCH_CONDITION.CssClass = "csstextboxreadonly";
                        txtZXMC.ReadOnly = true;
                        txtZXMC.CssClass = "csstextboxreadonly";
                        txtYDZDGGQXZ.ReadOnly = true;
                        txtYDZDGGQXZ.CssClass = "csstextboxreadonly";
                        txtEDZDGGQXZ.ReadOnly = true;
                        txtEDZDGGQXZ.CssClass = "csstextboxreadonly";
                        txtSDZDGGQXZ.ReadOnly = true;
                        txtSDZDGGQXZ.CssClass = "csstextboxreadonly";
                        txtYGCZPYXZXX.ReadOnly = true;
                        txtYGCZPYXZXX.CssClass = "csstextboxreadonly";
                        txtYGCZPYXZSX.ReadOnly = true;
                        txtYGCZPYXZSX.CssClass = "csstextboxreadonly";
                        txtJGCZPYXZXX.ReadOnly = true;
                        txtJGCZPYXZXX.CssClass = "csstextboxreadonly";
                        txtJGCZPYXZSX.ReadOnly = true;
                        txtJGCZPYXZSX.CssClass = "csstextboxreadonly";
                        txtYGZDZPXZ.ReadOnly = true;
                        txtYGZDZPXZ.CssClass = "csstextboxreadonly";
                        txtYGZDYPXZ.ReadOnly = true;
                        txtYGZDYPXZ.CssClass = "csstextboxreadonly";
                        txtYGYDZPXZ.ReadOnly = true;
                        txtYGYDZPXZ.CssClass = "csstextboxreadonly";
                        txtYGYDYPXZ.ReadOnly = true;
                        txtYGYDYPXZ.CssClass = "csstextboxreadonly";
                        txtJGZDZPXZ.ReadOnly = true;
                        txtJGZDZPXZ.CssClass = "csstextboxreadonly";
                        txtJGZDYPXZ.ReadOnly = true;
                        txtJGZDYPXZ.CssClass = "csstextboxreadonly";
                        txtJGYDZPXZ.ReadOnly = true;
                        txtJGYDZPXZ.CssClass = "csstextboxreadonly";
                        txtJGYDYPXZ.ReadOnly = true;
                        txtJGYDYPXZ.CssClass = "csstextboxreadonly";
                        txtZGQXZ.ReadOnly = true;
                        txtZGQXZ.CssClass = "csstextboxreadonly";
                        txtIS_SHOW.ReadOnly = true;
                        txtIS_SHOW.CssClass = "csstextboxreadonly";
                        txtAREA_NAME.ReadOnly = true;
                        txtAREA_NAME.CssClass = "csstextboxreadonly";
                        txtUTYPE.ReadOnly = true;
                        txtUTYPE.CssClass = "csstextboxreadonly";
                        txtBIG1000JGCZPYXZXX.ReadOnly = true;
                        txtBIG1000JGCZPYXZXX.CssClass = "csstextboxreadonly";
                        txtBIG1000JGCZPYXZSX.ReadOnly = true;
                        txtBIG1000JGCZPYXZSX.CssClass = "csstextboxreadonly";
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            btnBack.Attributes["onclick"] = "javascript:window.location.href='DEV_STANDARD_LAMP_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strSEARCH_CONDITION = txtSEARCH_CONDITION.Text.Trim();
            string strZXMC = txtZXMC.Text.Trim();
            string strYDZDGGQXZ = txtYDZDGGQXZ.Text.Trim();
            string strEDZDGGQXZ = txtEDZDGGQXZ.Text.Trim();
            string strSDZDGGQXZ = txtSDZDGGQXZ.Text.Trim();
            string strYGCZPYXZXX = txtYGCZPYXZXX.Text.Trim();
            string strYGCZPYXZSX = txtYGCZPYXZSX.Text.Trim();
            string strJGCZPYXZXX = txtJGCZPYXZXX.Text.Trim();
            string strJGCZPYXZSX = txtJGCZPYXZSX.Text.Trim();
            string strYGZDZPXZ = txtYGZDZPXZ.Text.Trim();
            string strYGZDYPXZ = txtYGZDYPXZ.Text.Trim();
            string strYGYDZPXZ = txtYGYDZPXZ.Text.Trim();
            string strYGYDYPXZ = txtYGYDYPXZ.Text.Trim();
            string strJGZDZPXZ = txtJGZDZPXZ.Text.Trim();
            string strJGZDYPXZ = txtJGZDYPXZ.Text.Trim();
            string strJGYDZPXZ = txtJGYDZPXZ.Text.Trim();
            string strJGYDYPXZ = txtJGYDYPXZ.Text.Trim();
            string strZGQXZ = txtZGQXZ.Text.Trim();
            string strIS_SHOW = txtIS_SHOW.Text.Trim();
            string strAREA_NAME = txtAREA_NAME.Text.Trim();
            string strUTYPE = txtUTYPE.Text.Trim();
            string strBIG1000JGCZPYXZXX = txtBIG1000JGCZPYXZXX.Text.Trim();
            string strBIG1000JGCZPYXZSX = txtBIG1000JGCZPYXZSX.Text.Trim();

            if (gfValidate.Is_Integer(strIS_SHOW) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[IS_SHOW]不是有效的数字格式。");
                return;
            }
            if (gfValidate.Is_Integer(strUTYPE) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[UTYPE]不是有效的数字格式。");
                return;
            }

            DEV_STANDARD_LAMP m_DEV_STANDARD_LAMP = new DEV_STANDARD_LAMP();
            DEV_STANDARD_LAMP_BLL m_DEV_STANDARD_LAMP_BLL = new DEV_STANDARD_LAMP_BLL();

            m_DEV_STANDARD_LAMP.SEARCH_CONDITION = strSEARCH_CONDITION;
            m_DEV_STANDARD_LAMP.ZXMC = strZXMC;
            m_DEV_STANDARD_LAMP.YDZDGGQXZ = strYDZDGGQXZ;
            m_DEV_STANDARD_LAMP.EDZDGGQXZ = strEDZDGGQXZ;
            m_DEV_STANDARD_LAMP.SDZDGGQXZ = strSDZDGGQXZ;
            m_DEV_STANDARD_LAMP.YGCZPYXZXX = strYGCZPYXZXX;
            m_DEV_STANDARD_LAMP.YGCZPYXZSX = strYGCZPYXZSX;
            m_DEV_STANDARD_LAMP.JGCZPYXZXX = strJGCZPYXZXX;
            m_DEV_STANDARD_LAMP.JGCZPYXZSX = strJGCZPYXZSX;
            m_DEV_STANDARD_LAMP.YGZDZPXZ = strYGZDZPXZ;
            m_DEV_STANDARD_LAMP.YGZDYPXZ = strYGZDYPXZ;
            m_DEV_STANDARD_LAMP.YGYDZPXZ = strYGYDZPXZ;
            m_DEV_STANDARD_LAMP.YGYDYPXZ = strYGYDYPXZ;
            m_DEV_STANDARD_LAMP.JGZDZPXZ = strJGZDZPXZ;
            m_DEV_STANDARD_LAMP.JGZDYPXZ = strJGZDYPXZ;
            m_DEV_STANDARD_LAMP.JGYDZPXZ = strJGYDZPXZ;
            m_DEV_STANDARD_LAMP.JGYDYPXZ = strJGYDYPXZ;
            m_DEV_STANDARD_LAMP.ZGQXZ = strZGQXZ;
            m_DEV_STANDARD_LAMP.IS_SHOW = Convert.ToInt32(strIS_SHOW);
            m_DEV_STANDARD_LAMP.AREA_NAME = strAREA_NAME;
            m_DEV_STANDARD_LAMP.UTYPE = Convert.ToInt32(strUTYPE);
            m_DEV_STANDARD_LAMP.BIG1000JGCZPYXZXX = strBIG1000JGCZPYXZXX;
            m_DEV_STANDARD_LAMP.BIG1000JGCZPYXZSX = strBIG1000JGCZPYXZSX;

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_DEV_STANDARD_LAMP_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                m_DEV_STANDARD_LAMP.ID = m_DEV_STANDARD_LAMP_BLL.GetMax_ID();

                if (m_DEV_STANDARD_LAMP_BLL.Insert(m_DEV_STANDARD_LAMP) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_DEV_STANDARD_LAMP.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_DEV_STANDARD_LAMP_BLL.Update(m_DEV_STANDARD_LAMP, Convert.ToInt32(strID)) == true)
                {
                     gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
